package cn.anecansaitin.inet.mixins;

import cn.anecansaitin.inet.TranslateHelper;
import mcjty.lib.gui.widgets.ImageChoiceLabel;
import mcjty.lib.gui.widgets.Panel;
import mcjty.lib.gui.widgets.Widget;
import mcjty.rftoolsbase.api.xnet.channels.RSMode;
import mcjty.rftoolsbase.api.xnet.gui.IEditorGui;
import mcjty.xnet.modules.controller.client.AbstractEditorPanel;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Map;

@Mixin(AbstractEditorPanel.class)
public abstract class EditorPanelMixin implements IEditorGui {
    @Shadow
    private int x;
    @Shadow
    private int y;
    @Final
    @Shadow
    protected Map<String, Object> data;
    @Final
    @Shadow
    private Panel panel;
    @Final
    @Shadow
    protected Map<String, Widget<?>> components;

    @Shadow
    protected abstract void fitWidth(int w);
    @Shadow
    protected abstract void update(String var1, Object var2);

    @Override
    public IEditorGui redstoneMode(String s, RSMode rsMode) {
        int w = 14;
        fitWidth(w);
        ImageChoiceLabel redstoneMode = new ImageChoiceLabel()
                .choice("Ignored", TranslateHelper.getText("inet.controller.setting.button.redstone.tooltip.ignored"), AbstractEditorPanel.iconGuiElements, 1, 1)
                .choice("Off", TranslateHelper.getText("inet.controller.setting.button.redstone.tooltip.off"), AbstractEditorPanel.iconGuiElements, 17, 1)
                .choice("On", TranslateHelper.getText("inet.controller.setting.button.redstone.tooltip.on"), AbstractEditorPanel.iconGuiElements, 33, 1)
                .choice("Pulse", TranslateHelper.getText("inet.controller.setting.button.redstone.tooltip.pulse"), AbstractEditorPanel.iconGuiElements, 49, 1);
        switch (rsMode) {
            case IGNORED -> redstoneMode.setCurrentChoice("Ignored");
            case OFF -> redstoneMode.setCurrentChoice("Off");
            case ON -> redstoneMode.setCurrentChoice("On");
            case PULSE -> redstoneMode.setCurrentChoice("Pulse");
        }
        redstoneMode.hint(x, y, w, 14);
        data.put(s, rsMode.name());
        redstoneMode.event((newChoice) -> update(s, newChoice));
        panel.children(redstoneMode);
        components.put(s, redstoneMode);
        x += w;
        return this;
    }
}
